home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11599 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: EU.net!sun4nl!ittpub!ittpub!nntp
  2. Newsgroups: comp.lang.c++
  3. Subject: Re: static and dynamic classes in C++ ?
  4. Message-ID: <1996Mar15.134305.1807@ittpub>
  5. From: wil@ittpub.nl (Wil Evers)
  6. Date: 15 Mar 96 13:43:05 WET
  7. References: <3148472F.41C6@informatik.uni-siegen.de>
  8. Distribution: world
  9. Nntp-Posting-Host: lintilla
  10.  
  11. In article <3148472F.41C6@informatik.uni-siegen.de> Runu Knips  
  12. <plrunu@informatik.uni-siegen.de> writes:
  13.  
  14. > Hi people!
  15. > 1. Is it possible to declare a class in a way that only
  16. > dynamic instances of it may be declared ?
  17.  
  18. Yes. Declare your constructors private, and for each constructor, write a  
  19. corresponding public static member function called `make' or so that  
  20. returns a pointer to a newly allocated object by calling the private  
  21. constructor.  
  22.  
  23. > 2. Is it also possible to declare a class in a way that
  24. > only static (i.e. stack or data segment) instances may
  25. > be declared ?
  26.  
  27. No. You could declare a private operator new() for that class, but that  
  28. will not prevent embedding an object of that class in another  
  29. heap-allocated object.
  30.  
  31. - Wil
  32.